<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>修改个人信息</title>
    <script src="../lib/jquery-3.4.1.js"></script>
    <script src="../lib/constant.js"></script>
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
    <link rel="stylesheet" href="../lib/layui/css/layui.css">
</head>
<body>
<div class="layui-form-item myFormItem">
    <label class="layui-form-label">手机号</label>
    <div class="layui-input-block">
        <input type="text" id="tele" placeholder="" autocomplete="off" class="layui-input"  style="border: none;" disabled="disabled">
    </div>
</div>
<div class="layui-form-item myFormItem">
    <label class="layui-form-label">姓名</label>
    <div class="layui-input-block">
        <input type="text" id="name" placeholder="请输入姓名" autocomplete="off" class="layui-input" maxlength="16">
    </div>
</div>
<div class="layui-form-item myFormItem">
    <label class="layui-form-label">地址(选填)</label>
    <div class="layui-input-block">
        <input type="text" id="address" placeholder="请输入地址" autocomplete="off" class="layui-input" maxlength="50">
    </div>
</div>
<div class="layui-form-item" style="text-align: center;">
    <button id="submit" class="layui-btn" style="padding-left: 30px;padding-right: 30px;margin:auto;width: 200px;">保存修改</button>
    <a href="home.html"><button class="layui-btn" style="width: 60px;margin: 0 auto;">返回</button></a>
</div>

</body>
<script>
    var tele;
    $(function () {
        $.ajax({
            type: 'get',
            url: RequestURL + '/getUserInfo',
            success: function (data) {
                $("#tele").val(data.tele);
                $("#name").val(data.name);
                $("#address").val(data.address);
                tele=data.tele;
            }
        });

        //点击提交将tele，name，address三个字段封装发送到cotroller
        $("#submit").click(function () {
            let name = $("#name").val().trim();
            let address = $("#address").val().trim();
            if (name == '' || name == null) {
                alert("请输入姓名");
                return false;
            }
            $.ajax({
                type: 'post',
                url: RequestURL + '/editUser',
                data: {
                    "tele": tele,
                    "name": name,
                    "address": address
                },
                success: function (data) {
                    alert("修改成功");
                    location.reload();
                }
            });
        });
    });


</script>
</html>